package com.zj.leetcode.easy;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: algorithm
 * @description:
 * 506 相对名次
 * @author: Zhang Bo
 * @create: 2022-01-13 16:27
 **/
public class RelativeRanks {
    public static void main(String[] args) {
        int[] score = new int[]{5,4,3,2,1};
        Solution solution = new RelativeRanks().new Solution();
        System.out.println(Arrays.toString(solution.findRelativeRanks(score)));
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String[] findRelativeRanks(int[] score) {

            String[] ret = new String[score.length];
            HashMap<Integer, String> map = new HashMap<>();

            List<Integer> list =
                    Arrays.stream(score)
                            .boxed()
                            .sorted(Comparator.reverseOrder())
                            .collect(Collectors.toList());

            for (int i = 0; i < list.size(); i++) {
                switch (i){
                    case 0:
                        map.put(list.get(i), "Gold Medal");
                        break;
                    case 1:
                        map.put(list.get(i), "Silver Medal");
                        break;
                    case 2:
                        map.put(list.get(i), "Bronze Medal");
                        break;
                    default:
                        map.put(list.get(i), Integer.toString(i + 1));
                }
            }

            for (int i = 0; i < score.length; i++) {
                ret[i] = map.get(score[i]);
            }

            return ret;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
